class Solution:
    def sortedSquares(self, nums: list[int]) -> list[int]:
        nums.append(9999)
        n = len(nums)
        i = 0
        j = 0
        while i < n-1:
            if nums[i] < 0 :
                nums[i] = -nums[i]
                j += 1
                i += 1
                continue
            if nums[i] >= 0:
                #如果新数组的最小值在两个数之间就插入
                if  nums[i]<= nums[j-1] <=nums[i+1] and j != 0:
                    nums.insert(i+1,nums[j-1])
                    nums.pop(j-1)
                    j = j-1
                    i = i-1
                    continue
                nums[i] = nums[i]*nums[i]
            i += 1
        nums.pop(-1)
        return nums
if __name__ == "__main__":
    test = Solution()
    print(test.sortedSquares([-7,-3,2,3,11]))